﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page isELIgnored="false" %>
<title>更新</title>
<<style type="text/css">
#authDiv{
    }

    #authDiv ul{
        margin:0px;
        padding:0px;
        list-style-type:none;
        vertical-align:middle  ;
    }

    #authDiv li{
        float:left;
        display:block;

        width:100px;  
        height:20px;
        line-height:20px;

        font-size:14px;   
        font-weight:bold;           
        color:#666666;

        text-decoration:none;
        text-align:left;  

        background:#ffffff;
    }
</style>

<script type="text/javascript">
/**
 * 查找数组中是否存在某一个元素
 */
function contains(arr, obj) {  
    var i = arr.length;  
    while (i--) {  
        if (arr[i] === obj) {  
            return true;  
        }  
    }  
    return false;  
}  

/**
 * 获取数据函数
 */
function getData(url){
	var result;
	$.get(url,function(data,status){
		result = eval("("+data+")");
	});
	alert();
	return result;
}

function getAndShowAuths(){
	$.get("auth/all",function(data,status){
		var allAuths = data.data;
		console.log("allAuths:" + allAuths);
		$.get("admin/auths/${admin.adminId}" ,function(data,status){
			var auths = data.data;
			console.log("auths:" + auths);	
			var ul=document.createElement("ul");
		    for(var i=0;i<allAuths.length;i++){
		        var auth=allAuths[i];

		        // 加入复选框
		        var checkBox=document.createElement("input");
		        checkBox.setAttribute("type","checkbox");
		        checkBox.setAttribute("id","authIds");
		        checkBox.setAttribute("value",auth.authId);
		        checkBox.setAttribute("name", "authIds");
		        // 判断用户拥有的权限
		        if(contains(auths, auth.authId)){
		        	checkBox.setAttribute("checked", true);
		        }
		        var li=document.createElement("li");
		        li.appendChild(checkBox);        
		        li.appendChild(document.createTextNode(auth.authName));
		        ul.appendChild(li);        
		    }
		    document.getElementById("authDiv").appendChild(ul);
		});
	});
 }
 getAndShowAuths();
</script>
	<div class="panel admin-panel">
		<div class="panel-head" id="add">
			<strong><span class="icon-pencil-square-o"></span>修改管理员</strong>
		</div>
		<div class="body-content">
			<form method="post" class="form-x" action="admin/modify">
			<input type="hidden" id="adminId" name="adminId" value="${admin.adminId}">
				<div class="form-group">
					<div class="label">
						<label>管理员账号: </label>
					</div>
					<div class="field">
						<input type="text" value="${admin.account}" class="input w50"
							name="account"
							data-validate="required:请输入管理员账号" />
						<div class="tips"></div>
					</div>
				</div>
				<div class="form-group">
					<div class="label">
						<label>管理员邮箱: </label>
					</div>
					<div class="field">
						<input type="text" value="${admin.email}" class="input w50"
							name="email"
							data-validate="required:请输入管理员邮箱" />
						<div class="tips"></div>
					</div>
				</div>
				<div class="form-group">
					<div class="label">
						<label>管理员头像：</label>
					</div>
					<div class="field">
						<div id="preview_div">
							<img id="preview_img" style="width: 200px; height: 200px;" src="${admin.head}">
						</div>
						<a href="javascript:;" class="file">选择图片
						<input class="serverImg" type="text" id="headImg" value="${admin.head}" name="head" />
						
						<input type="file" id="img" name="img" onchange="previewImage(this,'headImg');">
						</a>
						<div class="tipss">
						尺寸: 200*200 大小:0-50KB 
						</div>
					</div>
				</div>

				<div class="form-group">
					<div class="label">
						<label>管理员权限：</label>
					</div>
					<div class="field">
						<div id="authDiv"></div>
						<div class="tips"></div>
					</div>
				</div>
				<div class="clear"></div>

				<div class="form-group">
					<div class="label">
						<label></label>
					</div>
					<div class="field">
						<button class="button bg-main icon-check-square-o" type="submit">
							提交</button>
					</div>
				</div>
			</form>
		</div>
	</div>